package com.charging.controller;

import com.charging.bean.SiteImage;
import com.charging.config.config.BaseController;
import com.charging.util.aliOSS.OSS_File;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.prefs.BackingStoreException;

/**
 * 上传文件
 */
@Controller
@RequestMapping("admin/file")
public class FileController extends BaseController {

    @RequestMapping(value = "/uploadFile", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "文件上传")
    public Object  uploadFile(MultipartFile file)throws Exception {

        /**
         * OSS上传文件到服务器
         */
        OSS_File oss_file = new OSS_File();
        String a =  OSS_File.uploadImage(file.getOriginalFilename(), file.getInputStream());
        System.out.println("文件名:"+file.getOriginalFilename());
        System.out.println("文件路径:"+a);
        Map map = new HashMap();
        map.put("code",0);
        map.put("msg","上传成功");
        map.put("data",a);

        return map;
    }

    //商品信息多文件上传
    @RequestMapping(value = "/upload", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "文件上传")
    public Object  upload(MultipartFile file)throws Exception {
        OSS_File oss_file = new OSS_File();
        String a =  OSS_File.uploadImage(file.getOriginalFilename(), file.getInputStream());
        SiteImage siteImage = new SiteImage();
        siteImage.setUrl(a);
        siteImageService.save(siteImage);
        System.out.println("文件名:"+file.getOriginalFilename());
        System.out.println("文件路径:"+a);
        Map map = new HashMap();
        map.put("code",0);
        map.put("msg","上传成功");
        map.put("data",siteImage.getId());
        return map;
    }



}
